package com.sinbader.xiaole.common.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.UserKit;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import com.sinbader.xiaole.common.model.xiaolevo.BaseProductStockSearch;
import com.sinbader.xiaole.common.model.params.BaseProductStockSearchParam;
import com.sinbader.xiaole.common.mapper.BaseProductStockSearchMapper;
import com.sinbader.xiaole.common.service.BaseProductStockSearchService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinbader.xiaole.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 商品信息表 服务实现类
 * </p>
 *
 * @author LuoYong
 * @since 2020-04-20
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BaseProductStockSearchServiceImpl extends ServiceImpl<BaseProductStockSearchMapper, BaseProductStockSearch> implements BaseProductStockSearchService {
    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(BaseProductStockSearchServiceImpl.class);

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    /**
     * 查询当前用户所在门店的 商品库存信息
     *
     * @param productParam 参数
     * @return
     */
    public LayuiPageInfo selectProductStockInfos(BaseProductStockSearchParam productParam) {
        User currentOptUser = UserKit.getUser();
        if (StringUtils.equals("shop", currentOptUser.getType())) {
            productParam.setShopId(currentOptUser.getOrgId());
        }
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.selectProductStockInfos(pageContext, productParam);
        return LayuiPageFactory.createPageInfo(page);
    }
}
